#
# This file loads the version information
#


# load the strings from "hardware/arduino/boards.txt"
file(STRINGS ${ARDUINO_VERSION_FILE} ARDUINO_VERSION_STRINGS)
# for each string...
foreach(v ${ARDUINO_VERSION_STRINGS})
  string(REGEX MATCH "." dot "${v}")
  if( NOT dot )
    set(ARDUINO_VERSION_MAJOR "0")
    set(ARDUINO_VERSION_MINOR "${v}")
    set(ARDUINO_VERSION_REL   "0")
    set(ARDUINO_VERSION_FULL "0.${v}")
    set(ARDUINO_VERSION "${v}")
  else()
    string(REGEX MATCH "^[^.]+" ARDUINO_VERSION_MAJOR ${v})
    string(REGEX MATCH "[.].+[.]" u ${v})
    string(REGEX MATCH "[^.]+" ARDUINO_VERSION_MINOR ${u})
    string(REGEX MATCH "[^.]+$"   ARDUINO_VERSION_REL ${v})
    set(ARDUINO_VERSION_FULL "${v}")

    string(LENGTH "${ARDUINO_VERSION_MINOR}" len)
    if( len EQUAL 1 )
      set(ARDUINO_VERSION_MINOR "0${ARDUINO_VERSION_MINOR}")
    endif()
    set(ARDUINO_VERSION "${ARDUINO_VERSION_MAJOR}${ARDUINO_VERSION_MINOR}")
  endif()

  add_definitions(
    #-DARDUINO_VERSION_MAJOR=${ARDUINO_VERSION_MAJOR}
    #-DARDUINO_VERSION_MINOR=${ARDUINO_VERSION_MINOR}
    #-DARDUINO_VERSION=${ARDUINO_VERSION}
    -DARDUINO=${ARDUINO_VERSION}
    )

  message(STATUS "Arduino ${ARDUINO_VERSION_FULL} : -DARDUINO=${ARDUINO_VERSION} ")
  #message(STATUS "Arduino version: ${ARDUINO_VERSION}")
  #message(STATUS "Arduino major: ${ARDUINO_VERSION_MAJOR}")
  #message(STATUS "Arduino minor: ${ARDUINO_VERSION_MINOR}")
endforeach()

